<!--
 * @Description: 
 * @Author: wgy
 * @CreateTime: 2022-12-18 23:12:20
 * @UpdateTime: 2022-12-18 23:16:36
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 定义一个容器 -->
    <div id="box"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-domm库 用于操作dom -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入props库 用于操作props -->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    <!-- 引入babel,用于将jsx转换为js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">
        // 创建一个组件，组件首字母大写
        class MyComponent extends React.Component {
            // 相当于一个提前创建好的ref,两个不同的元素绑定相同ref会替换
            myRef1 = React.createRef()
            myRef2 = React.createRef()

            showData1 = () => {
                alert(this.myRef1.current.value)
            }

            showData2 = () => {
                alert(this.myRef2.current.value)
            }

            render() {
                return (
                    <div>
                        <input type="text" ref={this.myRef1} placeholder="请输入数字并点击" /><br />
                        <button onClick={this.showData1}>点击</button><br />
                        <input type="text" ref={this.myRef2} onBlur={this.showData2} placeholder="请输入数字并且失去焦点" />
                    </div>
                )
            }
        }

        // 渲染元素
        ReactDOM.render(<MyComponent />, document.getElementById("box"))

    </script>
</body>

</html>